home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Snippets / Toolbox / Tabs LDEF 1.0 / Sources / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-11  |  2.8 KB  |  177 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Events.c
  3.  
  4.     Contains:    Main event loop and basic keyboard/mouse processing
  5.  
  6.     Written by:    Chris White, Developer Technical Support
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.     
  12.             12/18/95            CW        First release
  13.  
  14. */
  15.  
  16.  
  17. #pragma segment Core
  18.  
  19.  
  20. // System Includes
  21.  
  22. #ifndef __MEMORY__
  23.     #include <Memory.h>
  24. #endif
  25.  
  26. #ifndef __APPLEEVENTS__
  27.     #include <AppleEvents.h>
  28. #endif
  29.  
  30. #ifndef __DIALOGS__
  31.     #include <Dialogs.h>
  32. #endif
  33.  
  34. #ifndef __DESK__
  35.     #include <Desk.h>
  36. #endif
  37.  
  38. #ifndef __WINDOWS__
  39.     #include <Windows.h>
  40. #endif
  41.  
  42.  
  43.  
  44.  
  45. // Application includes
  46.  
  47. #ifndef __BAREBONES__
  48.     #include "BareBones.h"
  49. #endif
  50.  
  51. #ifndef __PROTOTYPES__
  52.     #include "Prototypes.h"
  53. #endif
  54.  
  55.  
  56.  
  57.  
  58. // static includes
  59.  
  60. static void DoMouseDown ( EventRecord* theEvent );
  61. static void DoKey ( EventRecord*theEvent );
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. void EventLoop ( void )
  69. {
  70.     OSErr            theErr;
  71.     EventRecord        theEvent;
  72.     
  73.     
  74.     while ( !gQuit )
  75.     {
  76.         WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );    
  77.         
  78.         switch ( theEvent.what )
  79.         {
  80.             case mouseDown: 
  81.                 DoMouseDown ( &theEvent );
  82.             break;
  83.             
  84.             case keyDown:
  85.             case autoKey: 
  86.                 DoKey ( &theEvent );
  87.             break;
  88.             
  89.             case activateEvt: 
  90.                 DoActivate ( &theEvent );
  91.             break;
  92.             
  93.             case updateEvt:
  94.                 DoUpdate ( &theEvent );
  95.             break;
  96.             
  97.             case osEvt:
  98.                 if ( (theEvent.message >> 24) & suspendResumeMessage )    // suspend or resume
  99.                 {
  100.                     // Modify the event record to look like an activate/deactivate event
  101.                     theEvent.modifiers = theEvent.message;        // Copy suspend/resume flag
  102.                     theEvent.message = (long) FrontWindow ( );    
  103.                     DoActivate ( &theEvent );
  104.                 }
  105.             break;
  106.             
  107.             case kHighLevelEvent:
  108.                 theErr = AEProcessAppleEvent ( &theEvent );
  109.             break;
  110.         }
  111.     }
  112.     
  113.     return;
  114.     
  115. } // EventLoop
  116.  
  117.  
  118.  
  119. static void DoMouseDown ( EventRecord* theEvent )
  120. {
  121.     Point            globalPt = theEvent->where;
  122.     SInt16            windowPart;
  123.     WindowRef        theWindow;
  124.     long            theMenu;
  125.     
  126.     
  127.     windowPart = FindWindow ( globalPt, &theWindow );
  128.     switch ( windowPart )
  129.     {
  130.         case inMenuBar: 
  131.             theMenu = MenuSelect ( globalPt );
  132.             MenuDispatch ( theMenu );
  133.         break;
  134.         
  135.         case inSysWindow:
  136.             // The SystemClick toolbox routine handles system events
  137.             SystemClick ( theEvent, theWindow );
  138.         break;
  139.         
  140.         case inGoAway:
  141.             // We'll quit when the user closes the window
  142.             if ( TrackGoAway ( theWindow, theEvent->where ) )
  143.                 gQuit = true;
  144.         break;
  145.         
  146.         case inDrag:
  147.             DoDragWindow ( theWindow, theEvent );
  148.         break;
  149.  
  150.         case inContent:
  151.             DoContentClick ( theWindow, theEvent );
  152.         break;
  153.     }
  154.     
  155.     return;
  156.     
  157. } // DoMouseDown
  158.  
  159.  
  160.  
  161. static void DoKey ( EventRecord* theEvent )
  162. {
  163.     char keyPressed = (theEvent->message & charCodeMask);
  164.     
  165.     
  166.     // Command keys get handled by the menu handling routines
  167.     if ( theEvent->modifiers & cmdKey )
  168.         MenuDispatch ( MenuKey ( keyPressed ) );
  169.     
  170.     return;
  171.     
  172. } // DoKey
  173.  
  174.  
  175.  
  176.  
  177.